package org.zty.service;
import java.util.List;
import org.zty.common.BaseService;
import org.zty.db.DBMgr;
import org.zty.domain.Pojo;

import java.sql.SQLException;
import org.zty.util.ZException;
public class PojoService extends BaseService {
	public PojoService() {
		this.client = DBMgr.getSqlMapClient();
	}
	public Pojo insertPojo(Pojo pojo) throws ZException{
		try {
			if(pojo.getId()==0){
				int id = this.getNextId("pojo");
				pojo.setId(id);
			}
			this.client.insert("insertPojo",pojo);
			return pojo;
		} catch (SQLException e) {
			e.printStackTrace();
			throw new ZException("新增Pojo失败",e);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ZException("新增Pojo失败",e);
		}
	}
	public void deletePojo(Pojo pojo) throws ZException{
		try {
			this.client.delete("deletePojo",pojo);
		} catch (SQLException e) {
			e.printStackTrace();
			throw new ZException("删除Pojo失败",e);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ZException("删除Pojo失败",e);
		}
	}
	public void updatePojo(Pojo pojo) throws ZException{
		try {
			this.client.update("updatePojo",pojo);
		} catch (SQLException e) {
			e.printStackTrace();
			throw new ZException("修改Pojo失败",e);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ZException("修改Pojo失败",e);
		}
	}
	public Pojo getPojo(Pojo pojo) throws ZException{
		try {
			return (Pojo)this.client.queryForObject("findPojo",pojo);
		} catch (SQLException e) {
			e.printStackTrace();
			throw new ZException("获取单Pojo失败",e);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ZException("获取单Pojo失败",e);
		}
	}
	public int findPojoTotal(Pojo pojo) throws ZException{
		try {
			return (int)this.client.queryForObject("findPojoTotal",pojo);
		} catch (SQLException e) {
			e.printStackTrace();
			throw new ZException("获取总数Pojo失败",e);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ZException("获取总数Pojo失败",e);
		}
	}
	public List<Pojo> findAllPojo(Pojo pojo) throws ZException{
		try {
			return this.client.queryForList("findPojo",pojo);
		} catch (SQLException e) {
			e.printStackTrace();
			throw new ZException("获取所有Pojo失败",e);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ZException("获取所有Pojo失败",e);
		}
	}
	public List<Pojo> findPojoList(Pojo pojo) throws ZException{
		try {
			return this.client.queryForList("findPojo",pojo,pojo.getSkipSize(),pojo.getPageSize());
		} catch (SQLException e) {
			e.printStackTrace();
			throw new ZException("获取Pojo列表失败",e);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ZException("获取Pojo列表失败",e);
		}
	}
	public List<Pojo> findPojoPaginationList(Pojo pojo) throws ZException{
		try {
			return this.client.queryForList("findPaginationListPojo",pojo);
		} catch (SQLException e) {
			e.printStackTrace();
			throw new ZException("获取物理分页Pojo失败",e);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ZException("获取物理分页Pojo失败",e);
		}
	}
}